﻿var currentCss = "css/css/default/skin.css";
function getUISPContextPath() {
	var pathName = document.location.pathname;
	var index = pathName.substr(1).indexOf("/");
	var result = pathName.substr(0, index + 1);
	return result;
}

// 权限功能ID记录
var clickedFunctionId = "";
var currGuide = "1";
function ckId(obj) {
	if (obj.length == 8) {
		currGuide = "1";
	} else if (obj.length == 12) {
		currGuide = "2";
	} else if (obj.length == 16) {
		currGuide = "3";
	} else if (obj.length == 20) {
		currGuide = "4";
	}
	clickedFunctionId = obj;
}

// popMenu 效果
var strGuide = "";
jQuery.fn.extend({
	popMenu : function() {
		var cur;
		$("ul:not(:eq(0))", this).hide();// 除第一个外隐藏
		$("li:has(ul)", this).find("a:eq(0)").click(function() {// li里有ul的第一个是a的点击事件
					$(this).blur().next().slideDown().end().parent().parent()
							.find("ul:visible").not($(this).next()).slideUp();
					if ($(this).attr("href") == "#") {
						return false;
					} else {
						$(this).attr("href",
								decodeURIComponent($(this).attr("href")));
					}
				});

		var fourMenu = $("li a", this);
		fourMenu.click(function() {
					if (cur)
						cur.removeClass("current");
					cur = $(this).addClass("current");
					this.blur();
					if ($(this).attr("href") == "#"
							|| $(this).attr("href").indexOf("/main/index.jsp#") > -1) {// ie7下取出href非#号，而是url#
						return false;
					} else {
						$(this).attr("href",
								decodeURIComponent($(this).attr("href")));
						var icon = "&nbsp;<span class='point'></span>&nbsp;";

						var parentText1 = $(this).parent().parent().parent();
						if (currGuide == "3") {
							var text1 = $("a", parentText1.parent().parent())
									.html();
						} else {
							var text1 = $(
									"a",
									parentText1.parent().parent().parent()
											.parent()).html();
						}
						var text2 = $("a", parentText1.parent().parent())
								.html();
						var text3 = $("a", parentText1).html();
						if (text1.toLowerCase().indexOf("<span>") == "-1") {
							guide(1, text1.substring(text1.toLowerCase()
													.indexOf("\">")
													+ 2, text1.length), "");
						} else {
							guide(1, text1.substring(text1.toLowerCase()
													.indexOf("<span>")
													+ 6, text1.toLowerCase()
													.indexOf("</span>")), "");
						}
						guide(2, text2.substring(text2.toLowerCase()
												.indexOf("<span>")
												+ 6, text2.toLowerCase()
												.indexOf("</span>")), icon);
						guide(3, text3.substring(text3.toLowerCase()
												.indexOf("<span>")
												+ 6, text3.toLowerCase()
												.indexOf("</span>")), icon);
						guide(4, $(this).text(), icon);
					}
				})

	}
})

// 对ul上的my_menu添加效果，第一次装载时使用. (popupMenu、stackMenu通用)
function addPopMenu(menuId) {
	$('#my_menu' + menuId).popMenu();
}

addPopMenu('');

// 导航栏(序号顺序，文本)
function guide(num, lableText, icon) {
	/**
	 * for(var j = (num+1);j<=4;j++){
	 * document.getElementById("guide"+j).innerHTML = ""; }
	 * if(lableText.toLowerCase().replace(/(^\s*)|(\s*$)/g,'')!="<img"){
	 * document.getElementById("guide"+num).innerHTML = icon + lableText; }
	 */
}

// 隐藏头部
var hide = false;
var currentTop = 0; // 当前二三四级菜单距头部高度
var currentFrameId = "0";// 当前第几个菜单
function headerHidden(_t) {
	_t.headerFrame.style.marginTop = "-50px";
	document.getElementById('ttMenu').style.top = document
			.getElementById('ttMenu').offsetTop
			+ 0 + 'px';
	currentTop = currentTop - 50;
	if (currentFrameId != "0") {
		document.getElementById("my_span" + currentFrameId).style.top = currentTop
				+ "px";
	}
	hide = true;
	_t.logo.style.display = "none";
	_t.h = 38;
	_t.closeButton.className = "headerShow";
}

function headerShow(_t) {
	_t.headerFrame.style.marginTop = "0";
	document.getElementById('ttMenu').style.top = "32px";
	currentTop = currentTop + 50;
	if (currentFrameId != "0") {
		document.getElementById("my_span" + currentFrameId).style.top = currentTop
				+ "px";
	}
	hide = false;
	_t.logo.style.display = "";
	_t.h = 50;
	_t.closeButton.className = "headerHide";
}

var headerHide = {
	closeButton : document.getElementById("headerHide"),
	headerFrame : document.getElementById("topFrame"),
	logo : document.getElementById("logo"),
	h : 50,
	init : function() {
		var _t = this;
		_t.closeButton.onclick = function() {
			if (_t.h == 50) {
				headerHidden(_t);
			} else {
				headerShow(_t);
			}
		}
	}

};
headerHide.init();

// mainIframe窗体高度自适应 firefox下about:blank会不断增高，因此加入判断
function reinitIframe() {
	try {
		var iframe = document.getElementById("mainIframe");
		if (isSafari = navigator.userAgent.indexOf("Safari") > 0) {
			var idocument = iframe.contentWindow.document;
			var bHeight = idocument.body.scrollHeight;
			var indexHeight = document.documentElement.clientHeight;
			indexHeight = (indexHeight - 106);
			var height = Math.max(bHeight, indexHeight);
			iframe.height = height;
		} else {
			iframe.contentWindow
					.scroll(
							iframe.contentWindow.document.documentElement.scrollLeft,
							1);
			if (iframe.contentWindow.document.documentElement.scrollTop <= 0)
				return;
			iframe.height = parseInt(iframe.contentWindow.document.documentElement.scrollHeight
					+ 30)
					+ "px";
		}
	} catch (ex) {
	}

}
window.setInterval("reinitIframe()", 200);

/** 工作流驱动代码1 */
getUrlParamter = function(url, param) {
	var value = null;
	if (!url)
		url = document.URL;
	var paramsStr = url.split('?')[1];
	if (paramsStr) {
		var params = paramsStr.split('&');
		for (var i = 0; i < params.length; i++) {
			var temArrs = params[i].split('=');
			if (temArrs.length != 2) {
				continue;
			}
			if (temArrs[0] == param) {
				value = temArrs[1];
				break;
			}
		}
	}
	return value;
}

String.prototype.Trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

/** 工作流驱动代码2 */
hexToString = function(hex) {
	if (hex == null)
		return null;
	hex = hex.Trim();
	var len = hex.length;
	if (len == 0 || len % 2 == 1)
		return null;
	var str = '';
	for (var i = 0; i < hex.length; i += 2) {
		str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
	}
	return str;
}

// 欢迎页有条件展开,以及当一级菜单点击时是否隐藏头部、左侧
function show_smbs(functionId, flag, resultURL, event) {
	if (functionId != null && functionId != "") {
		ckId(functionId);
	}
	var mainIframe = document.getElementById("mainIframe");
	var mainPage = getUrlParamter(document.URL, 'mainPage');
	try {
		var v = event.srcElement ? event.srcElement : event.target;
		guide(1, v.innerHTML.split(">")[1], "");
	} catch (e) {
	}
	if (mainPage) {
		mainPage = hexToString(mainPage);
		mainIframe.src = "../" + mainPage;
	} else {
		if (resultURL != null && resultURL != "") {// 有空时firefox下会循环定向当前
			if (flag == null || flag == '' || flag == '0' || flag == 'null') {// 载入各模块欢迎main.html页
				try {
					mainIframe.contentWindow.document.location.href = resultURL;
				} catch (e) {
					mainIframe.src = resultURL;
				}
			} else {// 特殊处理的功能菜单 隐藏左侧菜单
				// hiddenMenuDIV();
				// 隐藏header
				if (flag == '4') {
					window.open(resultURL);
				} else {
					toggle999(true);// hide
					if (flag == '2') {
						closeHeader();
					}
					mainIframe.src = resultURL;
				}
			}
		}
	}
}

// 语言
function lang(lan) {
	// $("selectLg").value=JsSupport.getLanguagePath(false);//menuContentBean中返回调用
}

function closeHeader() {
	headerHidden(headerHide);
}

// 公告滚动
function start() {

}

// swichButton
function menuStage() {
	var hide = 0, sideBar = document.getElementById("mainLeft"), sep = document
			.getElementById("swichButton"), toggle = function() {
		if (hide === 0) {
			document.getElementById("guide").style.display = "none";
			sideBar.style.display = "none";
			sep.className = "swichClosed";
			hide = 1;
		} else {
			document.getElementById("guide").style.display = "";
			sideBar.style.display = "block";
			sep.className = "swichOpened";
			hide = 0;
		}
	}

	toggle999 = function(isHide) {
		if (isHide) {
			document.getElementById("guide").style.display = "none";
			sideBar.style.display = "none";
			sep.className = "swichClosed999";
		} else {
			document.getElementById("guide").style.display = "";
			sideBar.style.display = "block";
			sep.className = "swichOpened";
		}
	}
	sep.onclick = function() {
		toggle();
		return false;
	}
}

// 当点菜单以外文档时，隐藏菜单
window.onload = function() {
	try {
		go_smbs(window.event);
	} catch (e) {
	}
	new menuStage();
	var logo = currentCss == "css/default/skin.css" ? "logo2" : "logo4";
}